package com.example.firstapp.fragment

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import com.example.firstapp.R
import com.example.firstapp.databinding.ActivityNewsContentBinding
import com.example.firstapp.databinding.NewsContentFragBinding

class NewsContentFragment : Fragment() {
    private var _binding: NewsContentFragBinding? = null
    private val binding get() = _binding!!  // 安全访问

    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
        _binding = NewsContentFragBinding.inflate(inflater, container, false)
        return binding.root

    }
    override fun onDestroyView() {
        super.onDestroyView()
        _binding = null
    }
    fun refresh(title: String, content: String) {
        println(123)
        // 安全访问视图
        binding.contentlayout.visibility  = View.VISIBLE
        binding.newsTitle.text  = title // 刷新新闻标题
        binding.newsContent.text  = content // 刷新新闻内容
    }
}